package rabbitmq.consumer;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.MessageChannel;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 扇形交换机的消费者
 */
@Slf4j
@Component
public class FanoutConsumer {

    @RabbitListener(queues = "fanout_sms_queue")
    public void smsFanoutConsumer(String sms) {
        log.info(">>sms扇形消费者MSG:{}", sms);
    }

    @RabbitListener(queues = "fanout_email_queue")
    public void emailFanoutConsumer(String sms) {
        log.info(">>email扇形消费者MSG:{}", sms);
    }

    /**
     * 手动ack确认
     *
     * @param sms
     * @param message
     * @param channel
     * @throws IOException
     */
    @RabbitListener(queues = "fanout_emails_queue")
    public void emailFanout1Consumer(String sms, Message message, Channel channel) throws IOException {
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        log.info(">>email扇形消费者MSG:{}", sms);
    }
}
